import { dialog } from '@gis/lib/components/antd-dialog';
import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { hotelWarnMapPoint } from '@gis/lib/api';
import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import { openNetWarnListDialog } from '../../../../views/homestay-warning/homestay-warning-dialog.js';

/*
 * 网约房预警
 * */

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = 'wyfyj';
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  getLabelContent() {
    return `<div class="marker_label"><p class="marker_label__name">${this.data.yard_name}</p><p class="marker_label__count">当前预警：${this.data.hotel_warn_total}条</p></div>`;
  }

  onClick() {
    openNetWarnListDialog(this.data);
  }
}

export default class Wyfyj extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const data = await handleCommonRes(hotelWarnMapPoint, { area_code: area_code });
    //演示 - 所有未处理数据未“0”
    // return [];
    return data
      .filter((item) => item.longitude && item.latitude)
      .map((item) => Object.assign(item, { lnglat: [item.longitude, item.latitude] }));
  }
}
